package com.mrd.gtimp.base.service;

import com.mrd.gtimp.base.entity.SysMsg;
import com.mrd.gtimp.base.repository.ProcessDao;
import com.mrd.gtimp.base.repository.SysMsgSettingDao;
import com.mrd.gtimp.base.repository.SysMsgTemplateDao;

import org.springframework.stereotype.Service;

import java.util.Date;

import javax.annotation.Resource;

/**
 * 订舱业务流程中用于发送业务节点通知的实现类
 *
 * @author luob
 */
@Service
public class MsgSendBiz extends MsgSendAbstract {


    protected boolean send(String content) {
        return true;
    }


    @Resource
    public void setProcessDao(ProcessDao processDao) {
        super.processDao = processDao;
    }


    @Resource
    public void setSysMsgTemplateDao(SysMsgTemplateDao sysMsgTemplateDao) {
        super.sysMsgTemplateDao = sysMsgTemplateDao;
    }


    @Resource
    public void setSysMsgSettingDao(SysMsgSettingDao sysMsgSettingDao) {
        super.sysMsgSettingDao = sysMsgSettingDao;
    }


    protected boolean saveMsgHistory(String processId, String supCompanyId, String cusCompanyId,
                                     String content, String bizId, boolean supSendState, boolean cusSendState) throws Exception {
        SysMsg entity = new SysMsg();
        entity.setProcessId(processId);
        entity.setContents(content);
        entity.setConsumerId(cusCompanyId);
        entity.setConsumerState(cusSendState ? "1" : "0");
        entity.setCtime(new Date());
        entity.setSupId(supCompanyId);
        entity.setSupState(supSendState ? "1" : "0");
        entity.setBizId(bizId);
        sysMsgBiz.saveOrupdateEntity(entity);
        return true;
    }


    @Resource
    public void setSysMsgBiz(SysMsgBiz sysMsgBiz) {
        super.sysMsgBiz = sysMsgBiz;
    }

}
